package service.notice;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import vo.MemberVO;
import vo.NoticeVO;
import dao.examinfo.ExaminfoDAO;
import dao.interest.InterestDAO;
import dao.notice.NoticeDAO;
import dao.review.ReviewDAO;

public class NoticeServiceImpl implements NoticeService{

	private NoticeDAO noticeDAO;
	private InterestDAO interestDAO;
	private ReviewDAO reviewDAO;
	private ExaminfoDAO examinfoDAO;

	public void setInterestDAO(InterestDAO interestDAO) {
		this.interestDAO = interestDAO;
	}

	public void setNoticeDAO(NoticeDAO noticeDAO) {
		this.noticeDAO = noticeDAO;
	}

	public void setReviewDAO(ReviewDAO reviewDAO) {
		this.reviewDAO = reviewDAO;
	}

	public void setExaminfoDAO(ExaminfoDAO examinfoDAO) {
		this.examinfoDAO = examinfoDAO;
	}

	@Override
	public void sendNotice(int member_no, String notice_title, String notice_content) throws Exception {
		noticeDAO.sendNotice(new NoticeVO(new MemberVO(member_no), notice_title, notice_content));
	}

	@Override
	public void toInterestedMember(int majorunit_no, String notice_title, String notice_content) throws Exception{
		for(Integer member_no : interestDAO.getInterestedMember(majorunit_no)){
			sendNotice(member_no, notice_title, notice_content);
		}
	}

	@Override
	public void toWriters(int majorunit_no, String notice_title, String notice_content) throws Exception {
		List<Integer> reviewers=reviewDAO.getWriters(majorunit_no);
		List<Integer> examers=examinfoDAO.getWriters(majorunit_no);
		
		HashSet<Integer> writers=new HashSet<Integer>();
		
		for(int i:reviewers){
			writers.add(i);
		}
		for(int i:reviewers){
			examers.add(i);
		}
		
		Iterator<Integer> it=writers.iterator();
		
		while (it.hasNext()) {
			sendNotice(it.next(), notice_title, notice_content);
		}
	}
}
